import {recentThroughputStat} from '@/services/throughput-stat-api';
import {ActionType, ProColumns, ProTable} from '@ant-design/pro-components';
import React, {useRef} from 'react';
import {useLocation} from 'umi';


export type ThroughputStatProps = {
  pipelineId?:number;
}

const ThroughputStat: React.FC<ThroughputStatProps> = (props) => {

  const location = useLocation();
  // @ts-ignore
  const pipelineId = props?.pipelineId || location?.state?.pipelineId || null;

  /**
   * @en-US The pop-up window of the distribution update window
   * @zh-CN 分布更新窗口的弹窗
   * */
  const actionRef = useRef<ActionType>();
  const commonColumns: ProColumns<API.RecentThroughputStatDTO>[] = [
    {
      title: 'PipelineId',
      dataIndex: 'pipelineId',
      hideInSearch:true,
    },
    {
      title: '类型',
      dataIndex: ['type'],
      hideInSearch: true,
    },
    {
      title: 'TPS(1分钟)',
      dataIndex: ['recentThroughputStats','ONE_MINUTE','tps'],
      hideInSearch: true,
    },
    {
      title: 'TPS(5分钟)',
      dataIndex: ['recentThroughputStats','FIVE_MINUTE','tps'],
      hideInSearch: true,
    },
    {
      title: 'TPS(15分钟)',
      dataIndex: ['recentThroughputStats','FIFTEEN_MINUTE','tps'],
      hideInSearch: true,
    },
    {
      title: '吞吐量(1分钟)',
      dataIndex: ['recentThroughputStats','ONE_MINUTE','quantity'],
      hideInSearch: true,
    },
    {
      title: '吞吐量(5分钟)',
      dataIndex: ['recentThroughputStats','FIVE_MINUTE','quantity'],
      hideInSearch: true,
    },
    {
      title: '吞吐量(15分钟)',
      dataIndex: ['recentThroughputStats','FIFTEEN_MINUTE','quantity'],
      hideInSearch: true,
    },
    {
      title: '最后同步时间',
      dataIndex: ['gmtCreate'],
      hideInSearch: true,
    }
  ]

  return (
      <ProTable<API.RecentThroughputStatDTO, API.PageParams & any>
        actionRef={actionRef}
        rowKey="key"
        search={false}
        request={recentThroughputStat}
        pagination={false}
        params={{pipelineId:pipelineId}}
        columns={commonColumns}
      />
  );
};

export default ThroughputStat;
